import time
import ddddocr
import requests
import execjs


index_url = 'https://u.faloo.com/regist/Login.aspx'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
params = {
    "txtUserID": "asd854200524",
    "txtPwd": "d9a04c33ecf1546446ee5f37fa34064d",
    "txtPwd4temp": "",
    "verifyCode": "",
    "ts": "1692513466",
    "t": "2",
    "wx171155": "0820",
    "backurl": "http://www.faloo.com/",
    "mobileVerifyCode": "",
}
session = requests.session()
session.headers = headers


def validateCode():
    """识别验证码图片并保存session状态"""
    img_url = 'https://uimg.faloo.com/Common/ValidateImage.aspx?vt=login_code&lc=true&u=asd854200524&height=60&width=260&m=0.22130327238038894'
    img = session.get(img_url).content
    with open('1.jpg', 'wb') as f:
        f.write(img)
    ocr = ddddocr.DdddOcr()
    res = ocr.classification(img)  # 识别结果
    params['verifyCode'] = res
    print(res)
    return res


validateCode()
js_code = open('jscode.js', 'r', encoding='utf-8').read()
ts = int(time.time())
txtPwd = execjs.compile(js_code).call('getpwd', ts)
params['ts'] = ts
params['txtPwd'] = txtPwd
response = session.get(index_url, params=params)
html_text = response.content
with open('1.html', 'wb')as f:
    f.write(html_text)

